package com.haima.sage.bigdata.api.frame.filter;

import com.haima.sage.bigdata.api.frame.condition.impl.ConditionGroupService;

import java.io.IOException;
import java.util.Map;

public abstract class FilterService<T extends Filter> {
    protected T filter;
    protected ConditionGroupService conditionService;


    public FilterService(T filter) {
        this.filter = filter;
        if (this.filter.getCondition() != null) {
            this.conditionService = this.filter.getCondition().service();
        }
    }

    public Map<String, Object> filter(Map<String, Object> map) {
        boolean canDeal = true;
        if (conditionService != null) {
            canDeal = this.conditionService.deal(map);
        }
        if (canDeal) {
            return deal(map);
        }
        return map;
    }

    protected abstract Map<String, Object> deal(Map<String, Object> map);
}
